module FES3DT4_m
use AFES_m
use Mesh3DT4_m

type, extends(AFES) :: FES3DT4
    type(Mesh3DT4), pointer :: mesh3D
contains
    procedure, pass(this) :: getInfoPerNode => getInfoPerNodeT4
    procedure, pass(this) :: getInfoPerElement => getInfoPerElementT4
    procedure, pass(this) :: getInfoPerBoundary => getInfoPerBoundaryT4
end type

contains

subroutine getInfoPerNodeT4(this, i, coord)
    implicit none
    class(FES3DT4), intent(in) :: this
    integer, intent(in) :: i
    real*8, intent(out) :: coord(:)
    
    type(mesh3DT4), pointer :: mesh3D
    mesh3D => this%mesh3D
    coord = mesh3D%nodes(i)%xyz
end subroutine

subroutine getInfoPerElementT4(this, i, ele, label, coord)
    implicit none
    class(FES3DT4), intent(in) :: this
    integer, intent(in) :: i
    integer, intent(out) :: ele(:), label
    real*8, intent(out) :: coord(:, :)
    
    type(mesh3DT4), pointer :: mesh3D
    mesh3D => this%mesh3D
    ele = mesh3D%elements(i)%idx
    label = mesh3D%elements(i)%num
    coord(:, 1) = mesh3D%nodes(ele)%xyz(1)
    coord(:, 2) = mesh3D%nodes(ele)%xyz(2)
    coord(:, 3) = mesh3D%nodes(ele)%xyz(3)
end subroutine

subroutine getInfoPerBoundaryT4(this, i, ele, label, coord)
    implicit none
    class(FES3DT4), intent(in) :: this
    integer, intent(in) :: i
    integer, intent(out) :: ele(:), label
    real*8, intent(out) :: coord(:, :)
    
    type(Mesh3DT4), pointer :: mesh3D
    mesh3D => this%mesh3D
    ele = mesh3D%boundarys(i)%idx
    label = mesh3D%boundarys(i)%num
    coord(:, 1) = mesh3D%nodes(ele)%xyz(1)
    coord(:, 2) = mesh3D%nodes(ele)%xyz(2)
    coord(:, 3) = mesh3D%nodes(ele)%xyz(3)
end subroutine

end module